package cn.heygod.nacostool.config;

import cn.heygod.nacostool.session.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author Simon
 */
@Configuration
public class LoginConfig  implements WebMvcConfigurer {

    @Autowired
    private UserLoginInterceptor loginInterceptor;

    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(loginInterceptor);
        //所有路径都被拦截
//        registration.addPathPatterns("/api/**");
//        registration.addPathPatterns("/**/*.html");
        registration.addPathPatterns("/**");
        //添加不拦截路径
        registration.excludePathPatterns(
                "/**/api/login",
                "/**/api/logout",
                "/**/api/register",
                "/**/login.html",
                "/**/*.js",
                "/**/*.css"
        );
    }
}
